package hist.mobilprogramming.tictactoeapplication;

import static org.junit.Assert.*;
import org.junit.*;


public class GameEngineTests
{
	GameEngine _game;
	 /* Sets up the test fixture. 
     * (Called before every test case method.) 
     */ 
    @Before 
    public void setUp() 
    { 
    	_game = new GameEngine();
    } 

    /* Tears down the test fixture. 
     * (Called after every test case method.) 
     */ 
    @After 
    public void tearDown() 
    { 
         _game = null;
    } 

    @Test
	public void InitialConditionCorrectForObject()
	{
    	assertEquals(GameState.Ready ,_game.getState());
    	assertEquals(false ,_game.terminated());
	}
    
    @Test
	public void WhoseTurn_WhenStartingNewGame_IsPlayerX()
	{    	   
    	Player result = _game.WhoseTurn();
    	
		assertEquals(Player.X, result);
	}
    
    @Test
	public void OccupiedSpace_UnoccupiedWhenPlayerXStartsNewGame_ReturnFalse()
	{
    	boolean result = _game.OccupiedSpace(0, 0);
		assertEquals(false, result);
		result = _game.OccupiedSpace(0, 1);
		assertEquals(false, result);
		result = _game.OccupiedSpace(0, 2);
		assertEquals(false, result);
		
		result = _game.OccupiedSpace(1, 0);
		assertEquals(false, result);
		result = _game.OccupiedSpace(1, 1);
		assertEquals(false, result);
		result = _game.OccupiedSpace(1, 2);
		assertEquals(false, result);
		
		result = _game.OccupiedSpace(2, 0);
		assertEquals(false, result);
		result = _game.OccupiedSpace(2, 1);
		assertEquals(false, result);
		result = _game.OccupiedSpace(2, 2);
		assertEquals(false, result);
	}
    
    @Test
	public void WhoseTurn_AfterPlayerXIsFinished_IsPlayerOsTurn() throws ApplicationException
	{    	
    	_game.WhoseTurn();
    	_game.Play(0, 0);
    	
    	Player result = _game.WhoseTurn();
    	
		assertEquals(Player.O, result);
	}

    @Test
	public void OccupiedSpace_WhenSpaceIsAlreadyTakenByOneOfThePlayersItIsUnavailable_ReturnTrue() throws ApplicationException
	{	    	
    	_game.Play(0, 0);
    	
		boolean result = _game.OccupiedSpace(0, 0);
    	
    	assertEquals(true, result);
	}
    
    @Test  (expected=ApplicationException.class)
	public void Play_WhenPlayerTriesToTakeAnAlreadyOccupiedSpace_ThrowsException() throws ApplicationException
	{	    	
    	_game.Play(0, 0);    	
    	_game.Play(0, 0);
	}
    
    @Test (expected=ApplicationException.class)
	public void Play_WhenChoosenRowForSpaceIsOutOfRange_ThrowsException() throws ApplicationException
	{    	
    	_game.Play(3, 2);
	}
    
    @Test (expected=ApplicationException.class)
	public void Play_WhenChoosenColumnForSpaceIsOutOfRange_ThrowsException() throws ApplicationException
	{    	
    	_game.Play(0, 3);
	}
    
    @Test
	public void GetStatus_WhenPlayerXHasAchievedThreeOccupiedSpacesOnOneRow_PlayerWins() throws ApplicationException
	{    	
    	make_winGameByRow();

    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}

    @Test
	public void GetStatus_WhenPlayerOHasAchievedThreeOccupiedSpacesOnOneRow_PlayerWins() throws ApplicationException
	{
    	/* 		C1	 C2	  C3
    	 * 
    	 *	R1 	X(1) X(2) -
    	 * 	R2	O(1) O(2) O(3)
    	 *  R3  X(3) -	  -
    	 */
    	_game.Play(0, 0);
    	_game.Play(1, 0);
    	_game.Play(0, 1);
    	_game.Play(1, 1);
    	_game.Play(2, 0);
    	_game.Play(1, 2);

    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerO, result);
	}
 
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesOnOneColumn_PlayerWins() throws ApplicationException
	{
    	/* 		C1	 C2	  C3
    	 * 
    	 *	R1 	X(1) O(1) -
    	 * 	R2	X(2) O(2) -
    	 *  R3  X(3) -	  -
    	 */
    	_game.Play(0, 0);
    	_game.Play(0, 1);
    	_game.Play(1, 0);
    	_game.Play(1, 1);
    	_game.Play(2, 0);

    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
 
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLeftToRight_PlayerWins() throws ApplicationException
	{
   /* 	 		C1	 C2	  C3
    	 * 
    	 *	R1 	X(1) -	  O(1)
    	 * 	R2	- 	 X(2) O(2)
    	 *  R3  -	 -	  X(3)
    	 */
    	_game.Play(0, 0);
    	_game.Play(0, 2);
    	_game.Play(1, 1);
    	_game.Play(1, 2);
    	_game.Play(2, 2);

    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}

    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromRightToLeft_PlayerWins() throws ApplicationException
	{
    	 /*		C1	 C2	  C3
    	 * 
    	 *	R1 	X(1) X(2) O(1)
    	 * 	R2	- 	 O(2) -
    	 *  R3  O(3) -	  X(3)
    	 */
    	_game.Play(0, 0);
    	_game.Play(0, 2);
    	_game.Play(0, 1);
    	_game.Play(1, 1);
    	_game.Play(2, 2);
    	_game.Play(2, 0);
    	
    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerO, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerXShouldPlayNext_ExpectingPlayerXToTakeNewSpace() throws ApplicationException
	{
    	_game.Play(0, 0);
    	_game.Play(0, 2);
    	
    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.NextMoveByPlayerX, result);
	}    
    
    @Test
	public void GetStatus_WhenPlayerOShouldPlayNext_ExpectingPlayerOToTakeNewSpace() throws ApplicationException
	{
    	_game.Play(0, 0);
    	
    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.NextMoveByPlayerO, result);
	}
    
    @Test
	public void GetStatus_WhenAllSpacesAreOccupiedWhitoutWinner_GameIsDraw() throws ApplicationException
	{
    	make_drawGame();
    	
    	GameStatus result = _game.getStatus();
    	
		assertEquals(GameStatus.Draw, result);
	}
    
    @Test
	public void OccupiedSpace_WhenAllSpacesAreSet_ReturnTrue() throws ApplicationException
	{    	
    	make_drawGame();
    	
    	boolean result = _game.OccupiedSpace(0, 2);

    	assertEquals(true, result);
	}
    
    @Test
	public void OccupiedSpace_WhenGameIsSettled_ReturnTrue() throws ApplicationException
	{    	
    	make_winGameByRow();
    	
    	boolean result = _game.OccupiedSpace(2, 2);

    	assertEquals(true, result);
	}
    
    // More than 3x3
    @Test
	public void GetStatus_WhenPlayerXHasAchievedThreeOccupiedSpacesOnOneRowWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    	/* 		C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   X(1) X(2) X(3) -
    	 * 	R2	O(1) O(2) -		-	-
    	 *  R3	-	 -	  -		-	-
    	 *  R4	-	 -	  -		-	-
    	 *  R5  -	 -	  -		-	-
    	 */
		game.Play(0, 1);
    	game.Play(1, 0);
    	game.Play(0, 2);
    	game.Play(1, 1);
    	game.Play(0, 3);
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerXHasAchievedFiveOccupiedSpacesOnOneRow_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5, 5);
    	/* 		C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	X(1) X(2) X(3) X(4) X(5)
    	 * 	R2	O(1) O(2) O(3) O(4) -
    	 *  R3	-	 -	  -	   -	-	
    	 *  R4  -	 -	  -	   -	-
    	 *  R5  -	 -	  -	   -	-
    	 */
		
		game.Play(0, 0);
    	game.Play(1, 0);
    	game.Play(0, 1);
    	game.Play(1, 1);
    	game.Play(0, 2);
    	
    	game.Play(1, 2);
    	game.Play(0, 3);
    	game.Play(1, 3);
    	game.Play(0, 4);
		GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerXHasAchievedTwoOccupiedSpacesOnOneRowWhereMatrixDimensionIsFour_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
		/* 		C1	 C2	  C3   C4 
    	 * 
    	 *	R1 	 -   X(1) X(2) - 
    	 * 	R2	O(1) -	  -	   -
    	 *  R3	-	 -	  -	   -
    	 *  R4	-	 -	  -	   -
    	 */
		game.Play(0, 1);
    	game.Play(1, 0);
    	game.Play(0, 2);
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerXHasAchievedThreeOccupiedSpacesOnOneColumnWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    	/* 		C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   -    -    - 	-
    	 * 	R2	O(1) X(1) -	   -	-
    	 *  R3	O(2) X(2) -	   -	-
    	 *  R4	-	 X(3) -	   -	-
    	 *  R5  -	 -	  -	   -	-
    	 */
		game.Play(1, 1);
    	game.Play(1, 0);
    	game.Play(2, 1);
    	game.Play(2, 0);
    	game.Play(3, 1);
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
	
    @Test
	public void GetStatus_WhenPlayerXHasAchievedTwoOccupiedSpacesOnOneColumnWhereMatrixDimensionIsFour_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
		/* 		C1	 C2	  C3   C4 
    	 * 
    	 *	R1 	 -   X(1) -    - 
    	 * 	R2	O(1) X(2) -	   -
    	 *  R3	-	 -	  -	   -
    	 *  R4	-	 -	  -	   -
    	 */
		game.Play(0, 1);
    	game.Play(1, 0);
    	game.Play(1, 1);
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    //left to right
   @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLeftToRightWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    	 /*		C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   -    -    - 	-
    	 * 	R2	O(1) X(1) -	   -	-
    	 *  R3	O(2) -    X(2) -	-
    	 *  R4	-	 -    -    X(3)	-
    	 *  R5  -	 -	  -	   -	-*/
    	 
		game.Play(1, 1);
    	game.Play(1, 0);
    	game.Play(2, 2);
    	game.Play(2, 0);
    	game.Play(3, 3);
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}

    @Test
	public void GetStatus_WhenPlayerHasSetThreeSpacesWhereMatrixDimensionIsFive_NextMoveByPlayerO() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    	/* 		C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   -    -    - 	-
    	 * 	R2	O(1) X(1) -	   -	-
    	 *  R3	O(2) -    X(2) -	-
    	 *  R4	-	 -    -    -	-
    	 *  R5  -	 -	  -	   X(3) -
    	 */
		game.Play(1, 1);
    	game.Play(1, 0);
    	game.Play(2, 2);
    	game.Play(2, 0);
    	game.Play(4, 3);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.NextMoveByPlayerO, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLeftToRightInUpperRightCornerWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    	/* 		C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   -    X(1) - 	-
    	 * 	R2	O(1) -    -	   X(2)	-
    	 *  R3	O(2) -    -    -	X(3)
    	 *  R4	-	 -    -    -	-
    	 *  R5  -	 -	  -	   -	-
    	 */
		game.Play(0, 2);
    	game.Play(1, 0);
    	game.Play(1, 3);
    	game.Play(2, 0);
    	game.Play(2, 4);
    	//System.out.println(game.getPrintablePlayGrid());
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLeftToRightInLowerLeftCornerWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    	 /*		C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   -    -	   - 	-
    	 * 	R2	O(1) O(2) -	   -	-
    	 *  R3	X(1) -    -    -	-
    	 *  R4	-	 X(2) -    -	-
    	 *  R5  -	 -	  X(3) -	-
    	 */
		game.Play(2, 0);
    	game.Play(1, 0);
    	game.Play(3, 1);
    	game.Play(1, 1);
    	game.Play(4, 2);    	
    	//System.out.println(game.getPrintablePlayGrid());
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedTwoOccupiedSpacesDiagonallyFromLeftToRightInLowerMiddleWhereMatrixDimensionIsFour_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
    	 	/*	C1	 C2	  C3   C4  
    	 * 
    	 *	R1 	-	 -    -	   - 	
    	 * 	R2	O(1) -	  -	   -	
    	 *  R3	-	 -    X(1) -	
    	 *  R4	-	 -	  -    X(2)
    	     	*/
    	game.Play(2, 2);
    	game.Play(1, 0);
    	game.Play(3, 3);
    	//System.out.println(game.getPrintablePlayGrid());
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedTwoOccupiedSpacesDiagonallyFromLeftToRightInUpperLeftCornerWhereMatrixDimensionIsFour_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
    	 	/*	C1	 C2	  C3   C4  
    	 * 
    	 *	R1 	X(1) -    -	   - 	
    	 * 	R2	O(1) X(2) -	   -	
    	 *  R3	-	 -    -    -	
    	 *  R4	-	 -	  -    -*/
    	 
		game.Play(0, 0);
    	game.Play(1, 0);
    	game.Play(1, 1);    	
    	//System.out.println(game.getPrintablePlayGrid());
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedTwoOccupiedSpacesDiagonallyFromLeftToRightInLowerLeftCornerWhereMatrixDimensionIsFour_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
    	 	/*	C1	 C2	  C3   C4  
    	 * 
    	 *	R1 	-	 -    -	   - 	
    	 * 	R2	O(1) -	  -	   -	
    	 *  R3	X(1) -    -    -	
    	 *  R4	-	 X(2) -    -*/
    	 
		game.Play(2, 0);
    	game.Play(1, 0);
    	game.Play(3, 1);    	
    	//System.out.println(game.getPrintablePlayGrid());
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    //Right to left
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromRightToLeftInMiddleWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    		/*	C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   -    -    X(1) -
    	 * 	R2	O(1) -    X(2) -	-
    	 *  R3	O(2) X(3) -    -	-
    	 *  R4	-	 -    -    -	-
    	 *  R5  -	 -	  -	   -	-*/
    	 
		game.Play(0, 3);
    	game.Play(1, 0);
    	game.Play(1, 2);
    	game.Play(2, 0);
    	game.Play(2, 1);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    
    // Can be removed. The other two covers triangulation
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromRightToLeftInLowerLeftCornerWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    		/*	C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	 -   -    -    -	-
    	 * 	R2	O(1) -    X(1) -	-
    	 *  R3	O(2) X(2) -    -	-
    	 *  R4	X(3) -    -    -	-
    	 *  R5  -	 -	  -	   -	-*/
    	 
    	game.Play(1, 2);
    	game.Play(1, 0);
    	game.Play(2, 1);
    	game.Play(2, 0);
    	game.Play(3, 0);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromRightToLeftInUpperLeftCornerWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    		/*	C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	O(1) -    X(1) -	-
    	 * 	R2	O(2) X(2) -	   -	-
    	 *  R3	X(3) -    -	   -	-
    	 *  R4	-	 -    -    -	-
    	 *  R5  -	 -	  -	   -	-*/
    	 
		game.Play(0, 2);
    	game.Play(0, 0);
    	game.Play(1, 1);
    	game.Play(1, 0);
    	game.Play(2, 0);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromRightToLeftInLowerRightCornerWhereMatrixDimensionIsFive_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(5, 5);
    		/*	C1	 C2	  C3   C4   C5 
    	 * 
    	 *	R1 	O(1) -    -    -	-
    	 * 	R2	O(2) -	  -	   -	-
    	 *  R3	-	 -    -	   -	X(1)
    	 *  R4	-	 -    -    X(2)	-
    	 *  R5  -	 -	  X(3) -	-*/
    	 
		game.Play(2, 4);
    	game.Play(0, 0);
    	game.Play(3, 3);
    	game.Play(1, 0);
    	game.Play(4, 2);
    	//System.out.println(game.getPrintablePlayGrid());
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedTwoOccupiedSpacesDiagonallyFromRightToLeftInLowerRightCornerWhereMatrixDimensionIsFour_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
    	/*		C1	 C2	  C3   C4    
    	 * 
    	 *	R1 	O(1) -    -    -
    	 * 	R2	-	 -	  -	   -
    	 *  R3	-	 -    -	  X(1)
    	 *  R4	-	 -   X(2)  -*/
    	 
		game.Play(2, 3);
    	game.Play(0, 0);
    	game.Play(3, 2);
    	//System.out.println(game.getPrintablePlayGrid());
    	
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedTwoOccupiedSpacesDiagonallyFromRightToLeftInMiddleWhereMatrixDimensionIsFour_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
    	/*		C1	 C2	  C3   C4  
    	 * 
    	 *	R1 	 -   -    -    - 
    	 * 	R2	O(1) -    X(2) -	
    	 *  R3	-	X(3)  -    -	
    	 *  R4	-	 -    -    -		
    	 */
		game.Play(1, 2);
    	game.Play(1, 0);
    	game.Play(2, 1);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}   
    
    @Test
	public void GetStatus_WhenPlayersHasPlacedTwoOccupiedSpacesWhereMatrixDimensionIsFour_WaitForPlayerO() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(4, 4, 2);
    	/*		C1	 C2	  C3   C4  
    	 * 
    	 *	R1 	 -   -    -    - 
    	 * 	R2	O(1) -    X(2) -	
    	 *  R3	-	 - 	  -    -	
    	 *  R4	-	 -    -    X(3)		
    	 */
		game.Play(1, 2);
    	game.Play(1, 0);
    	game.Play(3, 3);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.NextMoveByPlayerO, result);
	}
    
    @Test
	public void GetStatus_WhenPlayerHasAchievedFiveOccupiedSpacesDiagonallyFromRightToLeftInUpperLeftCornerWhereMatrixDimensionIsTen_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(10, 10, 5);
    		/*	C1	 C2	  C3   C4   C5   C6	...
    	 * 
    	 *  R1 	-	 -    -	   -	X(1) -
    	 *  R2 	-	 -    -	   X(2)	-	 - 
    	 *	R3 	-	 -    X(5) -	-	 -
    	 * 	R4	-	 X(2) -	   -	- 	 -
    	 *  R5	X(3) -    -	   -	-	 -
    	 *  R6	O(1) O(2) O(3) O(4) -	 -
    	 *  R7  -	 -	  -	   -	-	 -
    	 *  .							 . ...
    	 *  .							 . ...
    	 *  */
    	 
		game.Play(0, 4);
    	game.Play(5, 0);
    	game.Play(1, 3);
    	game.Play(5, 1);
    	game.Play(2, 2);
    	game.Play(5, 2);
    	game.Play(3, 1);
    	game.Play(5, 3);
    	game.Play(4, 0);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}

    // Triangulate for test above
    @Test
	public void GetStatus_WhenPlayerHasAchievedFiveOccupiedSpacesDiagonallyFromRightToLeftInUpperLeftCornerWhereMatrixDimensionIs15_PlayerWins() throws ApplicationException
	{   
    	GameEngine game = new GameEngine(15, 15, 5);
    /*			C1	 C2	  C3   C4   C5 
    	 * 
    	 *  R1 	-	 -    -	   -	X(1)
    	 *  R2 	-	 -    -	   X(2)	-
    	 *	R3 	-	 -    X(5) -	-
    	 * 	R4	-	 X(2) -	   -	-
    	 *  R5	X(3) -    -	   -	-
    	 *  R6	O(1) O(2) O(3) O(4) -
    	 *  R7  -	 -	  -	   -	-
    	 *  
    */	 
		game.Play(0, 4);
    	game.Play(5, 0);
    	game.Play(1, 3);
    	game.Play(5, 1);
    	game.Play(2, 2);
    	game.Play(5, 2);
    	game.Play(3, 1);
    	game.Play(5, 3);
    	game.Play(4, 0);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}

    
	private void make_winGameByRow() throws ApplicationException
	{
		/* 		C1	 C2	  C3
    	 * 
    	 *	R1 	X(1) X(2) X(3)
    	 * 	R2	O(1) O(2) -
    	 *  R3	-	 -	  -
    	 */
		_game.Play(0, 0);
    	_game.Play(1, 0);
    	_game.Play(0, 1);
    	_game.Play(1, 1);
    	_game.Play(0, 2);
	}
    
	private void make_drawGame() throws ApplicationException
	{
		/* 		C1	 C2	  C3
    	 * 
    	 *	R1 	X(1) O(1) X(2)
    	 * 	R2	O(2) X(3) X(5)
    	 *  R3  O(3) X(4) O(4)
    	 */
		_game.Play(0, 0);
    	_game.Play(0, 1);
    	_game.Play(0, 2);
    	
    	_game.Play(1, 0);
    	_game.Play(1, 1);
    	_game.Play(2, 0);
    	
    	_game.Play(2, 1);
    	_game.Play(2, 2);
    	_game.Play(1, 2);
	}
	

	/*    // Start: Tests for optimazing diagonal winner search. Not finished..
	    // A
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromUpperLeftCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	X(3) -	  O(1) -
		   	 * 	R2	- 	 X(1) O(2) -
		   	 *  R3  -	 -	  X(2) -
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(1, 1);
		   	game.Play(0, 2);
		   	game.Play(2, 2);
		   	game.Play(1, 2);
		   	game.Play(0, 0);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}

	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLowerRightToLeftCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	X(2) -	  O(1) -
		   	 * 	R2	- 	 X(1) O(2) -
		   	 *  R3  -	 -	  X(3) -
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(1, 1);
		   	game.Play(0, 2);
		   	game.Play(0, 0);
		   	game.Play(1, 2);
		   	game.Play(2, 2);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromUpperLeftToRightCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	- 	 X(3) -	  O(1)
		   	 * 	R2	-	 - 	 X(1) O(2)
		   	 *  R3  -	 -	 -	  X(2)
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(1, 2);
		   	game.Play(0, 3);
		   	game.Play(2, 3);
		   	game.Play(1, 3);
		   	game.Play(0, 1);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	 
	    // B
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromUpperRightCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	-	 -	  O(1) X(3)
		   	 * 	R2	- 	 -    X(1) -
		   	 *  R3  -	 X(2) O(2) -
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(1, 2);
		   	game.Play(0, 2);
		   	game.Play(2, 1);
		   	game.Play(2, 2);
		   	game.Play(0, 3);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLowerLeftToRightCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	-	 -	 O(1) X(2)
		   	 * 	R2	-  	 -   X(1) -	  
		   	 *  R3  -	X(3) O(2) -	   
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(1, 2);
		   	game.Play(0, 2);
		   	game.Play(0, 3);
		   	game.Play(2, 2);
		   	game.Play(2, 1);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromUpperRightToLeftCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	-	 O(1) X(3) -
		   	 * 	R2	-    X(1)  -   -
		   	 *  R3  X(2) O(2)  -   -	
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(1, 1);
		   	game.Play(0, 1);
		   	game.Play(2, 0);
		   	game.Play(2, 1);
		   	game.Play(0, 2);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}

	    // Corners
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLowerLeftCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	-	 O(1) X(1) -
		   	 * 	R2	-	 X(2) -	   -
		   	 *  R3  X(3) O(2) -    -
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(0, 2);
		   	game.Play(0, 1);
		   	game.Play(1, 1);
		   	game.Play(2, 2);
		   	game.Play(2, 0);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromLowerRightCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3   C4	
		   	 * 
		   	 *	R1 	-	 X(1) -	  O(1) 
		   	 * 	R2	-	 - 	 X(2) O(2) 
		   	 *  R3  -	 -	 -	  X(3) 
		   	 
	    	GameManager game = new GameManager(3, 4);
		   	game.Play(0, 1);
		   	game.Play(0, 3);
		   	game.Play(1, 2);
		   	game.Play(1, 3);
		   	game.Play(2, 3);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    // Middle
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromMiddleLeftToUpperRightCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3  	
		   	 * 
		   	 *	R1 	-	 O(1) X(1) 
		   	 * 	R2	-	 X(2) -	   
		   	 *  R3  X(3) O(2) -   
		   	 *  R4  -	 -	  -
		   	 
	    	GameManager game = new GameManager(4, 3);
		   	game.Play(0, 2);
		   	game.Play(0, 1);
		   	game.Play(1, 1);
		   	game.Play(2, 2);
		   	game.Play(2, 0);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromMiddleLeftToLowerRightCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3  	
		   	 * 
		   	 *	R1 	-	 O(1) - 
		   	 * 	R2	X(3) O(2) -	   
		   	 *  R3  -    X(2) -   
		   	 *  R4  -	 -	  X(1)
		   	 
	    	GameManager game = new GameManager(4, 3);
		   	game.Play(3, 2);
		   	game.Play(0, 1);
		   	game.Play(2, 1);
		   	game.Play(1, 1);
		   	game.Play(1, 0);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    @Test
		public void GetStatus_WhenPlayerHasAchievedThreeOccupiedSpacesDiagonallyFromMiddleRightToLowerLeftCorner_PlayerWins() throws ApplicationException
		{
		 			C1	 C2	  C3  	
		   	 *  R1  -	 -	  -
		   	 *	R2 	-	 O(1) X(3) 
		   	 * 	R3	-	 X(2) -	   
		   	 *  R4  X(1) O(2) -   
		   	 
	    	GameManager game = new GameManager(4, 3);
		   	game.Play(3, 0);
		   	game.Play(1, 1);
		   	game.Play(2, 1);
		   	game.Play(3, 1);
		   	game.Play(1, 2);
		   	System.out.println(game.getPrintablePlayGrid());
		   	
		   	GameStatus result = game.getStatus();
	   	
			assertEquals(GameStatus.WonByPlayerX, result);
		}
	    
	    //
	    @Test
		public void GetStatus_WhenPlayerHasAchievedTwoOccupiedSpacesDiagonallyFromLowerRightCorner_NextMoveByPlayerO() throws ApplicationException
		{
	    	
	    	1 0 1 
	    	0 2 1 
	    	0 0 2 
	   		
		    GameManager game = new GameManager(3, 4);
		   	game.Play(0, 2);
		   	game.Play(1, 1);
		   	game.Play(1, 2);
		   	game.Play(2, 2);
		   	game.Play(0, 0);
		   	//System.out.println(game.getPrintablePlayGrid());
		   	
		 	GameStatus result = game.getStatus();
		   	
			assertEquals(GameStatus.NextMoveByPlayerO, result);
		 }
	    // End: Tests for optimazing diagonal winner search
	    */

	/* @Test
	public void GetStatus_WhenPlayerHasAchievedFiveOccupiedSpacesDiagonallyFromRightToLeftWhereMatrixDimensionIsTen_PlayerWins() throws ApplicationException
	{   
    	GameManager game = new GameManager(10, 10, 5);
    			C1	 C2	  C3   C4   C5	C6	C7  C8	C9	C10   
    	 *	R1 	 -   -    -    -	-	-	-	-	-	-	 
    	 * 	R2	O(1) -    -	   -	-	-	-	-	-	-	
    	 *  R3	-	 O(2) -    -	-	-	-	X(1)-	-	
    	 *  R4	-	 -    O(3) -	-	-	X(2)	-	-
    	 *  R5  -	 -	  -	   O(4) -	X(3)-	-	-	-
    	 *  R6  -	 -	  -    -	X(4)-	-	-	-	-
    	 *  R7  -	 -	  -	   X(5)	-	-	-	-	-	-	
    	 *  R8  -	 -	  -	   -	-	-	-	-	-	-	
    	 *  R9  .
    	 * R10  .	
    	 
		game.Play(2, 7);
    	game.Play(1, 0);
    	game.Play(3, 6);
    	game.Play(2, 1);
    	game.Play(4, 5);
    	game.Play(3, 2);    	
    	game.Play(5, 4);
    	game.Play(4, 3);
    	game.Play(6, 3);
    	//System.out.println(game.getPrintablePlayGrid());
    	GameStatus result = game.getStatus();
    	
		assertEquals(GameStatus.WonByPlayerX, result);
	}*/ 

}
